﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Live;

/**
 * 创建时间：2014/11/22 12:43:04
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace WCYCReader.ShareFolder
{
    public class GClass3
    {
        private BackgroundWorker backgroundWorker_0;
        private GClass0 gclass0_0;
        private aa aa_0;
        private IsolatedStorageFile isolatedStorageFile_0;
        private string string_0;
        private GClass5 gclass5_0;

        private string string_1;

        private LiveConnectSession liveConnectSession_0;

        private static Func<GClass1, bool> func_0;

        private static Func<GClass1, bool> func_1;

        private static Func<aw, bool> func_2;

        public string method_0()
        {
            return this.string_1;
        }

        public void method_1(string string_2)
        {
            this.string_1 = string_2;
        }

        public LiveConnectSession method_2()
        {
            return this.liveConnectSession_0;
        }

        public void method_3(LiveConnectSession liveConnectSession_1)
        {
            this.liveConnectSession_0 = liveConnectSession_1;
        }
        public BackgroundWorker method_4()
        {
            return this.backgroundWorker_0;
        }
        public GClass3(GClass0 gclass0_1, aa aa_1, string string_2, IsolatedStorageFile isolatedStorageFile_1)
        {
            this.backgroundWorker_0 = new BackgroundWorker();
            this.backgroundWorker_0.WorkerReportsProgress = true;//.set_WorkerReportsProgress(true);
            this.backgroundWorker_0.WorkerSupportsCancellation = true;// set_WorkerSupportsCancellation(true);
            this.gclass0_0 = gclass0_1;
            this.isolatedStorageFile_0 = isolatedStorageFile_1;
            this.string_0 = string_2;
            this.aa_0 = aa_1;
            this.backgroundWorker_0.DoWork += (new DoWorkEventHandler(this.backgroundWorker_0_DoWork));
        }
        public void method_5()
        {
            this.backgroundWorker_0.RunWorkerAsync();
        }
        public void method_6()
        {
            this.backgroundWorker_0.CancelAsync();
        }
        private void method_7(List<GClass1> list_0, GEnum0 genum0_0, BackgroundWorker backgroundWorker_1, DoWorkEventArgs doWorkEventArgs_0)
        {
            if (GClass3.func_0 == null)
            {
                GClass3.func_0 = new Func<GClass1, bool>(GClass3.smethod_0);
            }
            IEnumerable<GClass1> enumerable = Enumerable.Where<GClass1>(list_0, GClass3.func_0);
            if (GClass3.func_1 == null)
            {
                GClass3.func_1 = new Func<GClass1, bool>(GClass3.smethod_1);
            }
            IEnumerable<GClass1> enumerable2 = Enumerable.Where<GClass1>(list_0, GClass3.func_1);
            if (genum0_0 == GEnum0.const_0)
            {
                ushort a_ = this.aa_0.i(this.string_0);
                using (IEnumerator<GClass1> enumerator = enumerable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GClass1 current = enumerator.Current;
                        this.aa_0.i(a_, current.Path + "\\" + current.FileName);
                        if (backgroundWorker_1.CancellationPending)
                        {
                            doWorkEventArgs_0.Cancel = (true);
                            break;
                        }
                    }
                }
                if (!doWorkEventArgs_0.Cancel)
                {
                    using (IEnumerator<GClass1> enumerator2 = enumerable2.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            GClass1 current2 = enumerator2.Current;
                            List<aw> list = this.aa_0.i(this.string_0, current2.Path + "\\" + current2.FileName);
                            List<GClass1> list2 = new List<GClass1>();
                            IEnumerable<aw> arg_13A_0 = list;
                            if (GClass3.func_2 == null)
                            {
                                GClass3.func_2 = new Func<aw, bool>(GClass3.smethod_2);
                            }
                            using (IEnumerator<aw> enumerator3 = Enumerable.Where<aw>(arg_13A_0, GClass3.func_2).GetEnumerator())
                            {
                                while (enumerator3.MoveNext())
                                {
                                    aw current3 = enumerator3.Current;
                                    list2.Add(new GClass1
                                    {
                                        FileName = current3.a,
                                        Path = current2.Path + "\\" + current2.FileName,
                                        FileSize = current3.c,
                                        IsDirectory = current3.b
                                    });
                                }
                            }
                            this.method_7(list2, genum0_0, backgroundWorker_1, doWorkEventArgs_0);
                            this.aa_0.k(a_, current2.Path + "\\" + current2.FileName);
                        }
                    }
                }
                this.aa_0.h(a_);
                return;
            }
            if (genum0_0 == GEnum0.const_1)
            {
                using (IEnumerator<GClass1> enumerator4 = enumerable.GetEnumerator())
                {
                    while (enumerator4.MoveNext())
                    {
                        GClass1 current4 = enumerator4.Current;
                        this.isolatedStorageFile_0.DeleteFile("content\\" + current4.Path + "\\" + current4.FileName);
                        if (backgroundWorker_1.CancellationPending)
                        {
                            doWorkEventArgs_0.Cancel = (true);
                            break;
                        }
                    }
                }
                if (doWorkEventArgs_0.Cancel)
                {
                    return;
                }
                using (IEnumerator<GClass1> enumerator5 = enumerable2.GetEnumerator())
                {
                    while (enumerator5.MoveNext())
                    {
                        GClass1 current5 = enumerator5.Current;
                        List<GClass1> list3 = new List<GClass1>();
                        string[] directoryNames = this.isolatedStorageFile_0.GetDirectoryNames(string.Concat(new string[]
					{
						"content\\",
						current5.Path,
						"\\",
						current5.FileName,
						"\\*"
					}));
                        for (int i = 0; i < directoryNames.Length; i++)
                        {
                            string fileName = directoryNames[i];
                            list3.Add(new GClass1
                            {
                                FileName = fileName,
                                Path = current5.Path + "\\" + current5.FileName,
                                IsDirectory = true
                            });
                        }
                        string[] fileNames = this.isolatedStorageFile_0.GetFileNames(string.Concat(new string[]
					{
						"content\\",
						current5.Path,
						"\\",
						current5.FileName,
						"\\*"
					}));
                        for (int j = 0; j < fileNames.Length; j++)
                        {
                            string fileName2 = fileNames[j];
                            list3.Add(new GClass1
                            {
                                FileName = fileName2,
                                Path = current5.Path + "\\" + current5.FileName,
                                IsDirectory = false
                            });
                        }
                        this.method_7(list3, genum0_0, backgroundWorker_1, doWorkEventArgs_0);
                        this.isolatedStorageFile_0.DeleteDirectory("content\\" + current5.Path + "\\" + current5.FileName);
                    }
                    return;
                }
            }
            using (List<GClass1>.Enumerator enumerator6 = list_0.GetEnumerator())
            {
                while (enumerator6.MoveNext())
                {
                    GClass1 current6 = enumerator6.Current;
                    this.gclass5_0.method_19((current6 as GClass2).Id);
                    if (backgroundWorker_1.CancellationPending)
                    {
                        doWorkEventArgs_0.Cancel = (true);
                        break;
                    }
                }
            }
        }
        private void backgroundWorker_0_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (this.gclass0_0.method_0() == GEnum0.const_2)
                {
                    this.gclass5_0 = new GClass5(this.method_2());
                }
                this.method_7(this.gclass0_0.method_4(), this.gclass0_0.method_0(), sender as BackgroundWorker, e);
            }
            catch (Exception ex)
            {
                this.method_1(ex.Message);
                throw ex;
            }
        }

        private static bool smethod_0(GClass1 gclass1_0)
        {
            return !gclass1_0.IsDirectory;
        }

        private static bool smethod_1(GClass1 gclass1_0)
        {
            return gclass1_0.IsDirectory;
        }

        private static bool smethod_2(aw aw_0)
        {
            return aw_0.a != "." && aw_0.a != "..";
        }
    }
}
